<template>
    <div class="index-lists">
        <div style="display: flex; align-items: center">
            <el-button v-perms="['case:add']" type="primary" @click="handleAdd()">
                <template #icon>
                    <icon name="el-icon-Plus" />
                </template>
                新增案件
            </el-button>
            <el-form-item label="案件类型" prop="caseType" style="margin-top: 20px">
                <el-select v-model="queryParams.caseType" class="w-[280px]" clearable>
                    <el-option label="家族案件" value="1" />
                    <el-option label="技术相关" value="2" />
                    <el-option label="同日申请" value="3" />
                    <el-option label="同日递交" value="4" />
                </el-select>
            </el-form-item>
            <div style="margin-left: 20px">
                指定开卷信息关联勾选下面家族案件勾选框可关联（开卷案件数量超过一个可关联）
            </div>
        </div>
        <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
            <el-table-column label="相关案件" type="selection" width="55" />
            <el-table-column label="案件名称" prop="caseName" min-width="100" />
            <el-table-column label="我方文号" prop="ourRef" min-width="100" />
            <el-table-column label="客户文号" prop="customerDocumentNumber" min-width="100" />
            <el-table-column label="合同编号" prop="contractNumber" min-width="100" />
            <el-table-column label="申请类型" prop="putinType" min-width="100" />
            <el-table-column label="处理事项" prop="handlingInformation" min-width="100" />
            <el-table-column label="技术领域" prop="conductor" min-width="100" />
            <el-table-column label="国家（地区）" prop="designatedCountry" min-width="100" />
            <el-table-column label="承办部门" prop="undertakingDepartment" min-width="100" />
            <el-table-column label="处理人" prop="conductor" min-width="100" />
            <el-table-column label="指定处理人" prop="designatedCountry" min-width="100" />
            <el-table-column label="操作" width="120" fixed="right">
                <template #default="{ row }">
                    <el-button type="danger" link @click="handleAdd()">
                        <template #icon>
                            <el-icon><Close /></el-icon>
                        </template>
                    </el-button>
                    <el-button type="primary" link @click="handleAdd()">
                        <template #icon>
                            <el-icon><DocumentCopy /></el-icon>
                        </template>
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="flex justify-end mt-4">
            <pagination v-model="pager" @change="getLists" />
        </div>
        <el-dialog v-model="handlecopy" title="请选择要拷贝的内容">
            <el-form-item label="请选择需要复制的内容" prop="caseType">
                <el-checkbox-group
                    class="w-[740px]"
                    v-model="copytype"
                    placeholder="请选择需要复制的内容"
                >
                    <el-checkbox label="基本信息" value="1" disabled></el-checkbox>
                    <el-checkbox label="承办信息" value="2" disabled></el-checkbox>
                    <el-checkbox label="费用信息" value="5"></el-checkbox>
                    <el-checkbox label="优先权信息" value="3"></el-checkbox>
                    <el-checkbox
                        label="合同信息（往该合同中复制一条新的案件信息）"
                        value="6"
                    ></el-checkbox>
                </el-checkbox-group>
            </el-form-item>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="handlecopy = false">取消</el-button>
                    <el-button type="primary" @click="handlecopy = false"> 确定 </el-button>
                </div>
            </template>
        </el-dialog>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup name="case">
import { caseDelete, caseLists } from '@/api/case'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './uncoilEdit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const handlecopy = ref(false)
const copytype = ref(['基本信息', '承办信息'])
const queryParams = reactive({
    caseName: '',
    caseType: '',
    businessType: '',
    putinType: '',
    undertakingDepartment: '',
    conductor: '',
    taxRate: '',
    costType: '',
    cost: '',
    contributionPool: '',
    ownershipDistribution: '',
    haveCase: '',
    designatedCountry: '',
    brandType: '',
    classQuantity: '',
    quantity: '',
    officialFee: '',
    agencyFee: '',
    hirdPartyPayment: '',
    signedAmount: '',
    invoiceValue: '',
    fundsReceived: '',
    paidupDateStart: '',
    paidupDateEnd: '',
    planNumber: '',
    caseStatus: '',
    caseLink: '',
    remark: '',
    caseNameid: '',
    businessTypeid: '',
    undertakingDepartmentid: '',
    ownershipDistributionid: '',
    costTypeid: '',
    correlationTypeid: '',
    isRegister: '',
    isInvalid: '',
    isExistingcase: '',
    isPapernotice: '',
    customerDocumentNumber: '',
    copyrightType: '',
    caseFlow: '',
    countryOfOrigin: '',
    agency: '',
    proposalForm: '',
    isMaterials: '',
    isFund: '',
    initialPeriod: '',
    referenceNumber: '',
    contractNumber: '',
    budget: '',
    author: '',
    homeLocation: '',
    softwareAbbreviation: '',
    versionNumber: '',
    softwareWorkDescription: '',
    developmentCompletionDateStart: '',
    developmentCompletionDateEnd: '',
    publishedStatus: '',
    hardwareEnvironment: '',
    softwareEnvironment: '',
    programmingLanguage: '',
    sourceQuantity: '',
    functionAndArt: '',
    handlingInformation: '',
    principalDatesStart: '',
    principalDatesEnd: '',
    customerTermStart: '',
    customerTermEnd: '',
    internalWearLifeStart: '',
    internalWearLifeEnd: '',
    isStateCompensation: '',
    click: '',
    partOwner: '',
    todonote: '',
    manageDateStart: '',
    manageDateEnd: '',
    countType: '',
    numberOfPoints: '',
    addtotalstatepoint: '',
    royaltyDateStart: '',
    royaltyDateEnd: '',
    workPoints: '',
    creator: '',
    chargeType: '',
    currency: '',
    sum: '',
    advancePaymentDateStart: '',
    advancePaymentDateEnd: '',
    paymentRequestNumber: '',
    requestedDateStart: '',
    requestedDateEnd: '',
    accountsDateStart: '',
    accountsDateEnd: '',
    invoiceNumber: '',
    chargeName: '',
    chargeDepict: '',
    chargeDepictfine: '',
    extendedAmount: '',
    discountRate: '',
    count: '',
    parities: '',
    collectingCompanyAccount: '',
    collectionStatus: '',
    accountDetails: '',
    sltStart: '',
    sltEnd: '',
    externalBillingNumber: '',
    externalBillingDateStart: '',
    externalBillingDateEnd: '',
    beddingCondition: '',
    handOver: '',
    expenseNote: '',
    reductionType: '',
    actualCurrency: '',
    officialDeadlineStart: '',
    officialDeadlineEnd: '',
    ourRef: '',
    relevantCaseName: '',
    correlationType: '',
    userId: '',
    userName: '',
    updateUserId: '',
    updateUserName: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: caseLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await caseDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
